import Vue from 'vue'
import Router from 'vue-router'

// 组件导入，懒加载
const Home = () => import('../views/home/Home')
const Category = () => import('../views/category/Category')
const Profile = () => import('../views/profile/Profile')
const Store = () => import('../views/store/Store')

// 1.安装插件
Vue.use(Router)

const routes =  [
  {
    path:'',
    redirect:'/home'
  },
  {
    path:'/home',
    component:Home
  },
  {
    path:'/category',
    component:Category
  },
  {
    path:'/store',
    component:Store
  },
  {
    path:'/profile',
    component:Profile
  }
];

// 解决ElementUI导航栏中的vue-router在3.0版本以上重复点菜单报错问题
const originPush = Router.prototype.push;
Router.prototype.push = function push (location) {
  return originPush.call(this,location).catch(err => err)
}

// 2.创建router加导出
export default new Router({
  routes,
  mode:'history'
})
